package com.industrial.operation.controller;

import com.industrial.common.core.utils.StringUtils;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.web.page.TableDataInfo;
import com.industrial.common.security.annotation.RequiresPermissions;
import com.industrial.common.security.utils.SecurityUtils;
import com.industrial.operation.domain.OperationCompanyInfo;
import com.industrial.operation.domain.OperationMetric;
import com.industrial.operation.service.IOperationCompanyInfoService;
import com.industrial.operation.vo.OperationGroupAreaVo;
import com.industrial.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Array;
import java.util.*;
import java.util.regex.Pattern;

@RestController
@RequestMapping("/operationCompanyInfo")
public class OperationCompanyInfoController extends BaseController {

    @Autowired
    private IOperationCompanyInfoService operationCompanyInfoService;


    /**
     * 企业地市分布报表
     */
    @RequiresPermissions("conpanyInfo:conpanyInfo:list")
    @GetMapping("/list")
    public TableDataInfo list(OperationCompanyInfo operationCompanyInfo)
    {

        startPage();
        if(StringUtils.isNotNull(operationCompanyInfo.getCity())){
            LoginUser loginUser = SecurityUtils.getLoginUser();
            Set<String> roles= loginUser.getRoles();
            if(roles.contains("x_01_011")||roles.contains("along_yellow_river")){
                operationCompanyInfo.setVillage(operationCompanyInfo.getCity());
                operationCompanyInfo.setCity("");
            }else if(roles.contains("s_01_011")){
                operationCompanyInfo.setCounty(operationCompanyInfo.getCity());
                operationCompanyInfo.setCity("");
            }
        }

        List<OperationCompanyInfo>  list= operationCompanyInfoService.getByAreaList(operationCompanyInfo);
        return getDataTable(list);
    }

    /**
     * 图表
     * @param operationCompanyInfo
     * @return
     */
    @GetMapping(value = "/groupArea")
    public AjaxResult groupArea(OperationCompanyInfo operationCompanyInfo)
    {
        List<OperationGroupAreaVo>  list= operationCompanyInfoService.groupArea(operationCompanyInfo);
        List<String> xList=new ArrayList<>();
        List<String> yList=new ArrayList<>();
        for (OperationGroupAreaVo o :list) {
            if(StringUtils.isNotNull(o.getArea())){
                xList.add(o.getArea());
                yList.add(o.getNums());
            }
        }
        Map<String ,List<String>> map=new HashMap<String ,List<String>>(){
            {put("xlist",xList);
                put("ylist",yList);
            }
        };
        return success(map);
    }
}
